package com.hzhr.iot.collect.dao;

import com.hzhr.iot.collect.dao.mapper.custom.CollectLogEntityCustomMapper;
import com.hzhr.iot.collect.dao.mapper.generator.CollectLogEntityMapper;
import com.hzhr.iot.collect.entity.CollectLogEntity;
import com.hzhr.iot.collect.entity.ext.CollectLogEntityExt;
import com.hzhr.iot.collect.queryModel.custom.CollectLogCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class CollectLogDao {
    @Autowired
    CollectLogEntityMapper alarmDataEntityMapper;
    @Autowired
    CollectLogEntityCustomMapper alarmDataEntityCustomMapper;

    public int insert(CollectLogEntity record) {
        if (record == null) return 0;
        int changeCount = alarmDataEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(CollectLogCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = alarmDataEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(CollectLogEntity record) {
        if (record == null) return 0;
        int changeCount = alarmDataEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(CollectLogCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = alarmDataEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public CollectLogEntity selectEntity(CollectLogCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CollectLogEntityExt> extList = alarmDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CollectLogEntity> selectEntityList(CollectLogCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CollectLogEntityExt> extList = alarmDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<CollectLogEntity> entityList = new ArrayList<>();
        for (CollectLogEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public CollectLogEntityExt selectExt(CollectLogCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CollectLogEntityExt> extList = alarmDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CollectLogEntityExt> selectExtList(CollectLogCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CollectLogEntityExt> extList = alarmDataEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(CollectLogCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = alarmDataEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
